<?php

namespace app\job\event;

use app\api\model\settings\DicModel;
use app\common\library\sms\Driver as SmsDriver;
use app\common\model\settings\Setting as SettingModel;
use app\common\model\store\Clerk;
use app\common\model\order\Order as OrderModel;

/**
 * 拼团任务行为管理
 */
class AssembleBillMsg
{
    /**
     * 执行函数
     */
    public function handle($orderIds)
    {
        try {
            $orderList = (new OrderModel)->where('order_id', 'in', $orderIds)->select();
            foreach ($orderList as $order) {
                $clist = Clerk::where(['store_id' => $order['store_id'], 'is_send' => 1, 'is_delete' => 0])->select();
                $time = DicModel::listAll(['type' => 'sendTime'], [], 'sort_num desc');
                foreach ($clist as $citem) {
                    $smsConfig = SettingModel::getItem('sms', '10001');
                    $send_template = 'SMS_464455660';
                    $SmsDriver = new SmsDriver($smsConfig);
                    $mobile = $citem['mobile'];

                    $send_data = [
                        'time' => $time[0]['value']
                    ];
                    //$flag = $SmsDriver->sendSms($mobile, $send_template, $send_data);
                }
            }
        } catch (\Throwable $e) {
            echo 'ERROR AssembleBillMsg: ' . $e->getMessage() . PHP_EOL;
            log_write('AssembleBillMsg TASK : ' . '__ ' . $e->getMessage(), 'task');
        }
        return true;
    }


}
